package com.lishe.lishe.lishe.module.search.adapter;

import android.app.Activity;

import com.bumptech.glide.Glide;
import com.bumptech.glide.RequestManager;
import com.lishe.base.common.adapter.CommonAdapter;
import com.lishe.base.common.adapter.base.ViewHolder;
import com.lishe.lishe.Imageloader.ImageLoaderUtils;
import com.lishe.lishe.R;
import com.lishe.lishe.lishe.module.mall.activity.GoodsDetailActivity;
import com.lishe.lishe.lishe.module.search.bean.GoodsScreenBean;

import java.util.List;

/**
 * Created by Bin
 */

public class SearchResultAdapter extends CommonAdapter<GoodsScreenBean.DataBean.ItemsBean> {

    private final RequestManager requestManager;
    private List<GoodsScreenBean.DataBean.ItemsBean> mList;
    private Activity context;

    public SearchResultAdapter(Activity context, List<GoodsScreenBean.DataBean.ItemsBean> list) {
        super(context, R.layout.item_searchresult, list);
        this.mList = list;
        this.context = context;
        requestManager = Glide.with(context);
    }

    @Override
    protected void convert(ViewHolder holder, GoodsScreenBean.DataBean.ItemsBean goodsItemsBean, int position) {
        ImageLoaderUtils.displayTopRoundImage(context, goodsItemsBean.getImage_default_id(), holder.getView(R.id.goods_img), R.drawable.defalut_img);
        if ("43".equals(goodsItemsBean.getShop_id())) {
            holder.setText(R.id.jd_logo, "严选直供");
            holder.setVisible(R.id.jd_logo, true);
        } else if ("10".equals(goodsItemsBean.getShop_id())) {
            holder.setText(R.id.jd_logo, "京东直供");
            holder.setVisible(R.id.jd_logo, true);
        } else {
            holder.setVisible(R.id.jd_logo, false);
        }
        holder.setText(R.id.goods_name, goodsItemsBean.getTitle());
        holder.setText(R.id.price, "¥ " + goodsItemsBean.getPrice());
        holder.itemView.setOnClickListener(v -> GoodsDetailActivity.jump(context, mList.get(position).getItem_id()));

    }
}
